<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('carte服务监控')" />
</head>
<body class="gray-bg">
<div class="alert alert-warning" id="alert_warning">
    <strong>节点信息有变动，自动更新!</strong>
</div>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>节点名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>节点端口：</label>
                            <input type="text" name="nodePort"/>
                        </li>
                        <li>
                            <label>用户名称：</label>
                            <input type="text" name="nodeUsername"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('busi:node:edit')}]];
    var removeFlag = [[${@permission.hasPermi('busi:node:remove')}]];
    var prefix = ctx + "watchdog/node";
    var datas = [[${@dict.getType('sys_normal_disable')}]];

    $(function() {
        var options = {
            url: prefix + "/listMonitor",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "资源库节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'nodeId',
                    title: '节点ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '节点名称'
                },
                {
                    field: 'nodeHost',
                    title: '节点IP地址'
                },
                {
                    field: 'nodePort',
                    title: '节点端口'
                },
                {
                    field: 'nodeUsername',
                    title: '节点用户名称'
                },
                {
                    field: 'nodePassword',
                    title: '节点密码'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'runCount',
                    title: '运行任务次数',
                },
                {
                    field: 'runSuccessCount',
                    title: '运行任务成功次数',
                },
                {
                    field: 'runFailedCount',
                    title: '运行任务失败次数',
                },
                {
                    field: 'runningCount',
                    title: '正在运行任务数',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.getNodeStatus(\'' + row.nodeId + '\')"><i class="fa fa-edit"></i>健康检查</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="runDetail(\'' + row.nodeId + '\')"><i class="fa fa-edit"></i>运行情况</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        var _table = $.table;
        $("#alert_warning").hide();
        setInterval(function(){
            $.get("/getVersion","",function (data){
                if (window["updateState"]) {
                    if (window["updateState"]["carteMonitor"] != data) {
                        _table.refresh()
                        $("#alert_warning").show();
                        setTimeout(function () {
                            $("#alert_warning").hide();
                        }, 5000);
                        window["updateState"]["carteMonitor"] = data;
                    }
                } else {
                    window["updateState"] = {};
                    window["updateState"]["carteMonitor"] = 1;
                }
            })
        }, 1000);

        $.getNodeStatus = function (nodeId) {
            var url = prefix+ "/nodeStatus/"+nodeId;
            $.operate.submit(url, 'get', "json");
        }
    });

    function runDetail(slaveId) {
        var url = "/busi/executionLog/carteMonitorDetail/"+slaveId;
        $.modal.openTab("carte服务监控详情("+slaveId+")",url);
    }
</script>
</body>
</html>